<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String uri = request.getRequestURI();// 返回请求行中的资源名称
String contextPath = request.getContextPath();

%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <meta name="applicable-device" content="pc"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta http-equiv="Cache-Control" content="no-transform"/>
    <title>在线美食网 酒店 饭店 快餐 美食 </title>
    <meta name="keywords" content="在线美食网 酒店 饭店 快餐 美食 "/>
    <meta name="description" content="在线美食网 酒店 饭店 快餐 美食 "/>
    <link href="<%=path %>/css/index.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path %>/css/common1.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path %>/css/style.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="<%=path %>/js/jquery-1.12.4.min.js"></script>
	<script type="text/javascript" src="<%=path %>/js/pic.js"></script>
	<script type="text/javascript">
	//type==A，查询
	//type==B，排序，sortType==1：按访问量排序，sortType==2：按价格排序，sortType==3：按发布时间排序(初始化时默认按发布时间排序)
	//type==C，加载更多
	function sort(type,val){
		if(type==null){
			alert("排序异常!");
			return;
		}
		if(type=="A"){
			$("#currentPage").val(1);
		}
		//点击排序时用隐藏 input 记录当前所选排序框
		if(type=="B"){
			$("#sortType").val(val); 
			$("#currentPage").val(1);
		}
		//点击加载更多数据时，记录当前加载第几页
		if(type=="C"){
			var num = $("#currentPage").val();
			$("#currentPage").val(parseInt(num)+parseInt(1));
		}
		$.ajax({
		type : "POST",
		url : "<%=path %>/list/listDishes",
		data : {type:type,sortType:$("#sortType").val(),foodName:$('#foodName').val(),currentPage:$('#currentPage').val()},
		dataType : "json",
		async:false,
		success : function(obj) {
			if(obj!=null){
				var foodList = eval(obj);
				//点击查询和排序时，清空查询结果，重新显示
				//点击加载更多时，不清空页面，追加显示
				if(type=="A"||type=="B"){
					$("#foodUl li").remove();
				}
				for(var i=0;i<foodList.length;i++){
					if(foodList[i].name.length>10){
						foodList[i].name = foodList[i].name.substring(0,15)+"...）";
					}
				}
				for(var i=0;i<foodList.length;i++){
						var li = '<li><a href="<%=path %>/dishes/dishesDtail?id='+foodList[i].id+'"><img src="<%=path %>/'+foodList[i].topPic+'" width=218 '+
			            'height=168 title="'+foodList[i].name+'"/></a><p><a href="<%=path %>/dishes/dishesDtail?id='+foodList[i].id+'" target="_self" title="'+foodList[i].name+'" target="_blank" class="blue12">'+foodList[i].name+'</a><br/>'+
		                '商家：'+foodList[i].user.nickName+'<br/>'+
		                '人均：<span class="cf60">'+foodList[i].price+'</span>元&nbsp;&nbsp;<br/>'+
		                '访问量：<span class="cf60">'+foodList[i].focuse+'</span><br/>'+
		                '发布时间：<span class="cf60">'+viewDate(foodList[i].createTime)+'</span>';
						$("#foodUl").append(li);
			    }
			    if(foodList.length==8){
			    	$("#loadMore").show();	
			    }else{
			    	$("#loadMore").hide();
			    }
			}
		},
		error : function() {
			alert("网络连接出错！");
		}
		});
	}
	function viewDate(time){
		return (new Date(parseFloat(time))).format("yyyy-MM-dd hh:mm:ss");
	}
	Date.prototype.format = function(format) {
    var o = {
        "M+" : this.getMonth() + 1,// month
        "d+" : this.getDate(),// day
        "h+" : this.getHours(),// hour
        "m+" : this.getMinutes(),// minute
        "s+" : this.getSeconds(),// second
        "q+" : Math.floor((this.getMonth() + 3) / 3),// quarter
        "S" : this.getMilliseconds()
    // millisecond
    };
    if (/(y+)/.test(format) || /(Y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for ( var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
	};
	
</script>
</head>
<body>

<!--头部-->
<jsp:include page="../include/head.jsp">
	<jsp:param value="content" name="head" />
</jsp:include>

<!--导航-->
<jsp:include page="../include/nav.jsp">
	<jsp:param value="content" name="nav" />
</jsp:include>

<div class="h10"></div>
<div id="shop">
     <div class="sl_px" style="width: 800px">
       <input type="hidden" value=1 id="currentPage"/>
       <input type="hidden" value="createTime" id="sortType"/>
       <a rel="nofflow" href="javascript:sort('B','focuse')"  ><b>访问量↓</b></a>
       <a rel="nofflow" href="javascript:sort('B','price')"  ><b>价格↓</b></a>
       <a id="createTime" rel="nofflow" href="javascript:sort('B','createTime')"  ><b>发布时间↓</b></a>
       &nbsp;&nbsp;&nbsp;
       请输入美食名称：<input id="foodName" type="text"  /> <input type="button" onclick="sort('A',null)" value="搜索"/>
     </div>
     <div class="clear"></div>
	 <div id="foodList">
	    <c:forEach items="${dishesEntities}" var="information">
		   	<ul class="arial" id="foodUl">
		        <li><a href="<%=path %>/dishes/dishesDtail?id=${information.id}"><img src="<%=path%>${information.topPic}" width="218"
		                                                                     height="168" title="${information.name}"/></a>
		            <p>
		                <a href="<%=path %>/dishes/dishesDtail?id=${information.id}" target="_self" title="${information.name}" target="_blank" class="blue12">${information.name}</a><br/>
		                商家：${information.user.nickName}<br/>
		                人均：<span class="cf60">${information.price}</span>元&nbsp;&nbsp;<br/>
		                访问量：<span class="cf60">${information.focuse}</span><br/>
		                发布时间：<span class="cf60">${fn:substring(information.createTime, 0, 19)}</span>
		            </p>
		        </li>
		    </ul>
	     </c:forEach>
	 </div>
	 <div class="clear"></div>
	 <div id="loadMore" align="center">
       <a rel="nofflow" href="javascript:sort('C',null)" ><h3><b>
	 		加载更多
       </b></h3></a>
	 </div>
	  <div class="clear"></div>
	 <div>&nbsp;</div>
</div>
		

<!--页脚-->
<jsp:include page="../include/footer.jsp">
	<jsp:param value="content" name="head" />
</jsp:include>

</body>
</html>
